//
//  ADSuyiCustomAdapterTestSplashAd.m
//  ADSuyiCustomPlatform
//
//  Created by Erik on 2021/8/28.
//

#import "ADSuyiCustomAdapterTestSplashAd.h"
#import <BUAdSDK/BUSplashAdView.h>
@interface ADSuyiCustomAdapterTestSplashAd ()<BUSplashAdDelegate>

@property (nonatomic, strong) BUSplashAdView *splashAd;

@end

@implementation ADSuyiCustomAdapterTestSplashAd

+ (void)load {
    [self registPlatformAdLoaderClass:self forSdkName:@"toutiao" renderType:ADSuyiAdapterRenderTypeNative];
}

- (void)requestAdWithContext:(ADSuyiCustomAdapterRequestContext *)context {
    if (!_splashAd) {
        CGFloat width = UIScreen.mainScreen.bounds.size.width;
        CGFloat height = UIScreen.mainScreen.bounds.size.height - context.bottomView.frame.size.height;
        _splashAd = [[BUSplashAdView alloc] initWithSlotID:context.posId frame:CGRectMake(0, 0, width, height)];
        _splashAd.delegate = self;
        _splashAd.tolerateTimeout = 4;
        _splashAd.backgroundColor = [UIColor clearColor];
        _splashAd.hideSkipButton = YES;
    }
    [_splashAd loadAdData];
    
    [self trackSplashAdRequest];
}

#pragma mark - BUSplashAdDelegate

- (void)splashAdDidLoad:(BUSplashAdView *)splashAd {
    [self trackSplashAdSucceed];
    [self showSplashWithAdView:_splashAd customSkipBtn:YES];
}

- (void)splashAd:(BUSplashAdView *)splashAd didFailWithError:(NSError * _Nullable)error {
    [self trackSplashAdFailedWithError:error];
}

- (void)splashAdWillVisible:(BUSplashAdView *)splashAd {
    [self trackSplashAdDisplay];
}

- (void)splashAdDidClick:(BUSplashAdView *)splashAd {
    [self trackSplashAdClicked];
}

- (void)splashAdDidClose:(BUSplashAdView *)splashAd {
    [self trackSplashAdClosed];
}

- (void)splashAdDidCloseOtherController:(BUSplashAdView *)splashAd {
    
}

- (void)splashAdCountdownToZero:(BUSplashAdView *)splashAd {
    [self trackSplashAdClosed];
}


@end
